package dianmobile.eistarandroid.network.request;

import android.content.Context;

import com.android.volley.Response;

import org.xmlpull.v1.XmlPullParser;

import java.util.Map;

import dianmobile.eistarandroid.beans.UserInfo;
import dianmobile.eistarandroid.utils.ConstantsData;

public class UserDetailRequest extends ByhhAndroidRequest {

    public UserDetailRequest(int requestMethod, String url, Map<String, String> params,
                               RequestCallback callback, Response.ErrorListener listener){
        super(requestMethod, url, params, callback, listener);
    }

    public static void execute(Context context, Map<String, String> params, RequestCallback requestCallback) {
        executeSuper(context, RequestType.USER_DETAIL, params, requestCallback);
    }

    @Override
    protected void parseXmlToMap(XmlPullParser parser, Map<String, Object> result) {

        final String TAG_USERINFO = "userinfo";
        final String TAG_USER_ID = "userid";
        final String TAG_NICK = "nick";
        final String TAG_NUM_LOGIN = "numlogins";
        final String TAG_GENDER = "gender";
        final String TAG_HORO = "horoscope";
        final String TAG_LAST_LOGIN = "lastlogin";
        final String TAG_NEW_MAIL = "newmail";
        final String TAG_NUM_POSTS = "numposts";
        final String TAG_STRPOSTS = "strposts";
        final String TAG_NETAGE = "netage";
        final String TAG_STRNETAGE = "strnetage";
        final String TAG_LIFE = "life";
        final String TAG_EXP = "exp";
        final String TAG_STREXP = "strexp";
        final String TAG_MONEY = "money";
        final String TAG_STRMONEY = "strmoney";
        final String TAG_MEDALS = "medals";
        final String TAG_STRMEDALS = "strmedals";
        final String TAG_DUTY = "duty";
        final String TAG_INDIV = "individual";
        final String TAG_ONLINESTATE = "onlinestate";
        final String TAG_PLANS = "plans";

        UserInfo userInfo = new UserInfo();
        try {
            int event = parser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch (event) {
                    case XmlPullParser.START_DOCUMENT:
                        break;
                    case XmlPullParser.START_TAG:
                        String tagName = parser.getName();
                        if(tagName.equals(TAG_USERINFO)){

                        } else if (tagName.equals(TAG_USER_ID)) {
                            userInfo.setUserId(parser.nextText());
                        } else if (tagName.equals(TAG_NICK)) {
                            userInfo.setNickName(parser.nextText());
                        } else if (tagName.equals(TAG_NUM_LOGIN)) {
                            userInfo.setNumLogins(parser.nextText());
                        } else if (tagName.equals(TAG_GENDER)) {
                            userInfo.setGender(parser.nextText());
                        } else if (tagName.equals(TAG_HORO)) {
                            userInfo.setHoroscope(parser.nextText());
                        } else if (tagName.equals(TAG_LAST_LOGIN)) {
                            userInfo.setLastLogin(parser.nextText());
                        } else if (tagName.equals(TAG_NEW_MAIL)) {
                            userInfo.setNewMail(parser.nextText());
                        } else if (tagName.equals(TAG_NUM_POSTS)) {
                            userInfo.setNumPosts(parser.nextText());
                        } else if (tagName.equals(TAG_STRPOSTS)) {
                            userInfo.setStrPosts(parser.nextText());
                        } else if (tagName.equals(TAG_NETAGE)) {
                            userInfo.setNetAge(parser.nextText());
                        } else if (tagName.equals(TAG_STRNETAGE)) {
                            userInfo.setStrNetage(parser.nextText());
                        } else if (tagName.equals(TAG_LIFE)) {
                            userInfo.setLife(parser.nextText());
                        } else if (tagName.equals(TAG_EXP)) {
                            userInfo.setExp(parser.nextText());
                        } else if (tagName.equals(TAG_STREXP)) {
                            userInfo.setStrExp(parser.nextText());
                        } else if (tagName.equals(TAG_MONEY)) {
                            userInfo.setMoney(parser.nextText());
                        } else if (tagName.equals(TAG_STRMONEY)) {
                            userInfo.setStrMoney(parser.nextText());
                        } else if (tagName.equals(TAG_MEDALS)) {
                            userInfo.setMedals(parser.nextText());
                        } else if (tagName.equals(TAG_STRMEDALS)) {
                            userInfo.setStrMedals(parser.nextText());
                        } else if (tagName.equals(TAG_DUTY)) {
                            userInfo.setDuty(parser.nextText());
                        } else if (tagName.equals(TAG_INDIV)) {
                            userInfo.setIndividual(parser.nextText());
                        } else if (tagName.equals(TAG_ONLINESTATE)) {
                            userInfo.setOnlineState(parser.nextText());
                        } else if (tagName.equals(TAG_PLANS)) {
                            userInfo.setPlans(parser.nextText());
                        }
                        break;
                    case XmlPullParser.END_TAG:
                        break;
                    default:
                        break;
                }
                event = parser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        result.put(ConstantsData.USER_INFO, userInfo);

    }
}
